<template>

    <div class="app-container" v-if="canList">
        <!-- 查询 -->
        <div class="filter-container">
            <el-input v-if=" !isWg && roleId.indexOf(18) == -1" @keyup.enter.native="handleFilter" style="width: 200px;"
                      class="filter-item input"
                      placeholder="店铺名称"
                      v-model="listQuery.shopName">
            </el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item input"
                      placeholder="商品名称"
                      v-model="listQuery.name">
            </el-input>
            <el-select v-if="!isWg " @change='handleFilter' clearable class="filter-item input" style="width: 130px"
                       v-model="listQuery.shelf"
                       placeholder="库存上架">
                <el-option v-for="(item,index) in  adminShelfOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>

          <el-select  @change='handleFilter' clearable class="filter-item input" style="width: 130px"
                     v-model="listQuery.limitPayWay"
                     placeholder="限制支付">
            <el-option v-for="(item,index) in  limitPayWay" :key="item" :label="item" :value="index">
            </el-option>
          </el-select>


            <el-select v-if="userId == null" @change='handleFilter' clearable class="filter-item input"
                       style="width: 130px;margin-left: 10px"
                       v-model="listQuery.saleType"
                       placeholder="售卖类型">
                <el-option v-if="item != ''" v-for="(item,index) in  adminSaleTypeOptions" :key="item" :label="item"
                           :value="index">
                </el-option>
            </el-select>
            <el-cascader
                    placeholder="分类"
                    :options="mallTypes"
                    @change="handleFilter"
                    :props="queryProp"
                    v-model="types"
                    clearable
                    filterable>
            </el-cascader>

            <el-button style="margin-left: 10px;" class="filter-item input" type="primary" v-waves icon="el-icon-search"
                       @click="handleFilter">查询
            </el-button>
        </div>
        <!-- 列表 -->
        <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
                  style="width: 100%;min-height:1000px;">
            <el-table-column align="center" label="序号">
                <template slot-scope="scope">
                    <span>{{scope.row.id}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="店铺名称" width="150">
                <template slot-scope="scope">
                    <span>{{scope.row.shopEntity?scope.row.shopEntity.name:getShopName}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="商品名称" width="150">
                <template slot-scope="scope">
                    <span>{{scope.row.name}}</span>
                </template>
            </el-table-column>
          <el-table-column align="center" label="商品简称" width="150">
            <template slot-scope="scope">
              <span>{{scope.row.remark}}</span>
            </template>
          </el-table-column>
            <el-table-column align="center" label="单位">
                <template slot-scope="scope">
                    <span>{{scope.row.unit}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="库存">
                <template slot-scope="scope">
                    <span>{{scope.row.stock}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="库存上架">
                <template slot-scope="scope">
                    <span>
                          {{adminShelfOptions[scope.row.shelf]}}
                    </span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="售卖类型">
                <template slot-scope="scope">
                    <span>
                       {{adminSaleTypeOptions[scope.row.saleType]}}
                    </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="操作" width="230" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="warning" v-if="!userId&&canUpdate" size="mini" @click="handleStock(scope)">入库
                    </el-button>
                    <el-button type="primary" v-if="canUpdate" size="mini" @click="handleUpdate(scope.row)">编辑
                    </el-button>
                    <el-button v-if="canSave" size="mini" type="danger"
                               @click="handleDelete(scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>

        </el-table>
        <!-- 页码 -->
        <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                           layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
        <!-- 入库对话框 -->
        <el-dialog title="入库" center :visible.sync="dialogStockVisible" width="550px">
            <el-form ref="dataForm" label-position="left"
                     style='width: 50%; margin-left:10%;' label-width="80px">
                <el-form-item label="商品名称:" prop="name">
                    <el-input  v-model="stock.goodsName"  style="width:300px;"></el-input>
                </el-form-item>
                <el-form-item label="产品SKU" prop="name" v-if="temp.mallSkus&&temp.mallSkus.length>0">
                    <el-select @change="changeStockSku" v-model="stock.skuName" placeholder="请选择">
                        <el-option
                                v-for="item in temp.mallSkus"
                                :key="item.name"
                                :label="item.name"
                                :value="item.name">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="库存数量:" prop="unit">
                    <el-input type="number" disabled v-model="stock.oldQuantity" style="width:300px;"></el-input>
                </el-form-item>
                <el-form-item label="库存增量:" prop="unit">
                    <el-input type="number" v-model="stock.quantity"></el-input>
                </el-form-item>
                <el-form-item label="备注:" prop="unit">
                    <el-input type="textarea" v-model="stock.remark" style="width:300px;"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer"  class="dialog-footer">
                <el-button @click="dialogStockVisible=false" style="margin-right: 46px;">取消</el-button>
                <el-button @click="updateStock" type="primary">确认</el-button>
            </div>
        </el-dialog>
        <!-- 编辑对话框 -->
        <el-dialog :before-close="closeDialogForm"  :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="550px" center>
            <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px"
                     style='width: 70%; margin-left:50px;'>
                <el-form-item label="商品名称:" prop="name">
                    <el-input disabled v-model="temp.name"></el-input>
                </el-form-item>
              <el-form-item label="商品名称:" prop="name">
                <el-input disabled v-model="temp.remark"></el-input>
              </el-form-item>
                <el-form-item  label="商品分类:" prop="types" :show-all-levels="false">
                    <el-cascader
                            disabled
                            collapse-tags
                            v-model="fenLeiTypes"
                            :options="mallTypes"
                            :props="props"
                            @change="handleChange"
                            clearable></el-cascader>
                </el-form-item>
                <el-form-item label="售卖类型:" prop="saleType">
                    <el-select disabled @change="selectPrice" class="filter-item" v-model="temp.saleType" placeholder="售卖类型">
                        <el-option  v-if="item != ''" v-for="(item,index) in adminSaleTypeOptions" :key="item" :label="item"
                                    :value="index">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="库存数量:" prop="stock">
                    <el-input v-model="temp.stock" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"></el-input>
                </el-form-item>
                <el-form-item v-if="!userId&&temp.saleType==1&&!temp.userId"  label="预定上架" prop="">
                    <el-select  class="filter-item input"  v-model="temp.reserve" placeholder="是否预定">
                        <el-option v-for="(item,index) in  reserveShelfOptions"
                                   :key="index"
                                   :label="item"
                                   :value="index"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <!--<el-form-item v-if="userId != null" label="库存上架" prop="status">
                    <el-select disabled class="filter-item input"  v-model="temp.shelf" placeholder="是否上架">
                        <el-option v-for="(item,index) in  userShelfOptions" v-if="item!=''"
                                   :key="item"
                                   :label="item"
                                   :value="index"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item v-else label="库存上架:" prop="status">
                    <el-select :disabled="adjustFlag" class="filter-item input"  v-model="temp.shelf" placeholder="是否上架">
                        <el-option v-for="(item,index) in  adminShelfOptions"
                                   :key="item"
                                   :label="item"
                                   :value="index"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>-->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="closeDialogForm" style="margin-right: 46px;">取消</el-button>
                <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确认</el-button>
                <el-button v-else type="primary" @click="updateData">确认</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style type="stylus" lang="stylus">
    .filter-container {
        /*padding-bottom: 20px;*/
    }

    .filter-item {
        margin-bottom: 10px;
    }

    .filter-item.input {
        /*line-height: 60px*/
        margin-right: 10px;
    }

    .uploadImg {
        color: red;
        font-size: 12px
    }
    .imgNewDiv{
        pointer-events none
    }
</style>

<script>
    import UnloadImg from '@/components/UnloadImg'
    import {list, save, update, remove, info, updateStock, listType} from '@/api/mall_goods'
    import waves from '@/directive/waves' // 水波纹指令
    import {getList} from '@/api/shopLogTem'

    import {getToken, domain} from '@/api/qiniu'
    import {listToStrs, strsToList} from '@/utils/imgUtil'

    import {mapGetters} from 'vuex'
    import {hasAuth} from '@/utils/auth'
    import Sku from '@/components/Sku'
    import {listAll} from "../../../api/level";

    export default {
        name: 'test',
        directives: {
            waves
        },
        components: {
            Sku,UnloadImg
        },
        data() {
            return {
                priceFlag:false,
                shopReward:null,
                cashReward:null,
                voucherReward:null,
                clearReward:null,
                couponReward:null,
                supplyPrice:null,
                maxCoupon:null,
                maxClear:null,
                shopLogTemList:[],
                shopLogTems:["新增物流模板"],
                brandBusinessLicenseList: [],
                companyHealthLicenseList: [],
                manageHealthLicenseList: [],
                approveLicenseList: [],
                produceLicenseList: [],
                registerNoticeList: [],
                manageLicenseList: [],
                gmpLicenseList: [],
                trademarkLicenseList: [],
                productAgreementList: [],
                circulateLicenseList: [],
                betweenCirculateLicenseList: [],
                detectPhotocopyList: [],
                goodsDeclarationList: [],
                productListList: [],
                companyLicenseList: [],
                entrustAgreementList: [],
                qualityGuarantyList: [],
                healthPhotocopyList: [],
                fiveTrademarkList: [],
                recordTableList: [],
                epidemicPreventionList: [],
                industryLicenseList: [],
                salesAuthorizationList: [],
                testProveList: [],
                cccLicenseList: [],
                goodsProveList: [],
                brandAuthorizationList: [],
                bigTypes: [],
                userId: null,
                levels: null,
                tableKey: 0,
                list: null,
                total: null,
                listLoading: true,
                props: {multiple: true, label: "name", value: "id"},
                queryProp: {label: "name", value: "id"},
                mallTypes: [],
                fenLeiTypes: [],
                types: [],
                roleId: [],
                province: null,
                city: null,
                area: null,
                adjustFlag:true,
                saleTypeFlag:false,
                act: {
                    id: null,
                    name: null,
                    goodsId: null,
                    bindGoodsId: null,
                    bindGoodsQuantity: null,
                    skuId: null,
                    start: null,
                    end: null,
                    level: null,
                    number: null,
                    stock: null,
                    status: null
                },
                goodsTemp: {
                    id: null,
                    userId: null,
                    goodsId: null,
                    brandName: null,
                    brandInfo: null,
                    brandBusinessLicense: null,
                    companyHealthLicense: null,
                    manageHealthLicense: null,
                    approveLicense: null,
                    produceLicense: null,
                    registerNotice: null,
                    manageLicense: null,
                    gmpLicense: null,
                    trademarkLicense: null,
                    productAgreement: null,
                    circulateLicense: null,
                    betweenCirculateLicense: null,
                    detectPhotocopy: null,
                    goodsDeclaration: null,
                    productList: null,
                    companyLicense: null,
                    entrustAgreement: null,
                    qualityGuaranty: null,
                    healthPhotocopy: null,
                    fiveTrademark: null,
                    recordTable: null,
                    epidemicPrevention: null,
                    industryLicense: null,
                    salesAuthorization: null,
                    testProve: null,
                    cccLicense: null,
                    goodsProve: null,
                    brandAuthorization: null
                },
                listQuery: {
                    page: 1,
                    limit: 20,
                    order: 'sort'
                    ,
                    userId: null
                    ,
                    types: [],

                    type: null
                    ,
                    name: null
                    ,
                    unit: null
                    ,
                    sales: null
                    ,
                    weight: null
                    ,
                    info: null
                    ,
                    title: null
                    ,
                    oldPrice: null
                    ,
                    nowPrice: null
                    , shopPrice: null
                    ,
                    profit: null
                    ,
                    sort: null
                    ,
                    stock: null
                    ,
                    openSku: null
                    ,
                    shelf: null,
                    limitPayWay: null,
                    mode: null,
                    saleType: null,
                    shopName: null
                },
                adminSaleTypeOptions: ["分享有利", "代理有利", "新品体验", "复购折扣", "12元包邮", "门店采购", "营销工具", "", "", "", "", "", "", "", "", "", "", "清货", "聚优惠"],
                saleTypeOptions: ["分享有利", "代理有利", "新品体验", "", "", "门店采购","", "", "", "", "", "", "", "", "", "", "", "清货",],
                deliverState:["未发货","已发货"],
                reserveShelfOptions:["不可预订","可预订"],
                transferState:["未转货","已转货"],
                options: ["否", "是"],
                openSkuOptions: ["关闭", "开启"],
                dailySelOptions: ["关闭", "开启"],
                goodsShareOptions: ["活动信息", "卖点信息","关闭"],
                shelfOptions: ["下架", "上架"],
                userShelfOptions: ["下架","","上架审核"],
                adminShelfOptions: ["下架", "上架","待审核"],
                limitPayWay: ["不限制", "限制"],
                BookingShelves: ["不可预订", "可预订"],
                logTypeOptions: ["包邮", "满免", "计重"],
                tagTypes: ['info', '', 'warning', 'danger', 'warning'],
                stock: {
                    goodsId: null,
                    goodsName: null,
                    oldQuantity: null,
                    quantity: null,
                    remark: null,
                    skuName: null
                },
                saleTypeInfoEntity: {
                    id:null,
                    goodsId:null,
                    maxCoupon: null,
                    maxClear:null,
                    point: null,
                    transfer: null,
                    delivery: null,
                    couponReward: null,
                    voucherReward: null,
                    maxVoucher: null,
                    managerReward: null,
                    clearReward: null
                },
                flTypes: [],
                goodsShare:null,
                remnant: 200,//备注最大输入200个字符
                maxRemnant: 200,//备注最大输入200个字符
                shopPrice:null,
                temp:
                    {
                        id: null,
                        userId: null,
                        type: null,
                        name: null,
                        remark: null,
                        unit: null,
                        sales: null,
                        weight: null,
                        perBox: null,
                        info: null,
                        title: null,
                        oldPrice: null,
                        nowPrice: null,
                        shopPrice: null,
                        profit: null,
                        openSku: null,
                        img: null,
                        bigImg: null,
                        shelf: null,
                        sort: null,
                        expDate: null,
                        logType: null,
                        fullNumber: null,
                        reserve: null,
                        logFee: null,
                        stock: null,
                        midImg: null,
                        postImg: null,
                        prices: [],
                        saleType: null,
                        createTime: null,
                        guaranty: null,
                        discountInfo:null,
                        discountPrice:null,
                        actInfo:null,
                        buyTheme:null,
                        buyInfo:null,
                        logTemId:null,
                        dailySel:null,
                        supplyPrice:null,
                        shopEntity:null
                    },
                dialogFormVisible: false,
                dialogStockVisible: false,
                dialogStatus:
                    '',
                textMap:
                    {
                        update: '修改',
                        create:
                            '新增'
                    }
                ,
                // 存在图片
                dialogImageUrl: '',
                dialogVisible: false,
                imgList: [],
                bigImgList: [],
                midImgList: [],
                postImgList: [],
                imgDiv: 'imgDiv',
                rules:
                    {
                        cash_reward: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],

                        voucher_reward: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        logType: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        userId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        expDate: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        type: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        name: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        createTime: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        transfer: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        delivery: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        saleType: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        unit: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        sales: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        weight: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        info: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        title: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        oldPrice: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        shopPrice: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        nowPrice: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        profit: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        openSku: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        img: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        bigImg: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        shelf: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ],

                        sort: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        stock: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        guaranty: [
                            {
                                required: true, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        midImg: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        postImg: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        brandName: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ],
                        brandInfo: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                    }
                ,
                downloadLoading: false,
                qData:
                    {
                        token: '',
                        key:
                            ''
                    }
            }
        },
        created() {

            this.getList()
            this.getShopLogTemList()
            //获取所有级别
            listAll().then(res => {
                this.levels = res.data
            })
            //获取所有的分类
            listType().then(res => {
                this.mallTypes = res.data
            })
        },
        computed: {
            getShopName(){
                return process.env.VUE_APP_SHOPNAME;
            },
            isWg(){
                return process.env.VUE_APP_SHOPNAME == '五集时代';
            },
            ...mapGetters([
                'perms'
            ]),
            canSave() {
                return hasAuth(this.perms, 'mall:goods:save')
            },
            canDelete() {
                return hasAuth(this.perms, 'mall:goods:delete')
            },
            canUpdate() {
                return hasAuth(this.perms, 'mall:goods:update')
            },
            canList() {
                return hasAuth(this.perms, 'mall:goods:list')
            }
        },
        methods: {
            descInput(){
                var txtVal = this.temp.info.length;
                this.remnant = this.maxRemnant - txtVal;
            },
            selectPrice(index){
                this.cashReward = null
                this.voucherReward = null
                this.couponReward = null
                this.maxCoupon = null
                this.maxClear=null
                this.voucherReward = null
                this.temp.supplyPrice= null
                this.shopPrice= null
                this.temp.shopPrice = null
                this.saleTypeInfoEntity.cashReward = null
                this.saleTypeInfoEntity.voucherReward = null
                this.saleTypeInfoEntity.couponReward = null
                this.saleTypeInfoEntity.maxCoupon = null
                this.saleTypeInfoEntity.maxClear=null
                this.saleTypeInfoEntity.voucherReward = null
                if (index == 5){
                    this.cashReward = this.shopPrice?this.shopPrice * 0.1:null;
                    this.voucherReward = this.shopPrice?this.shopPrice * 0.1:null;
                }
            },
            getShopLogTemList() {
                getList().then(res => {
                    this.shopLogTemList = res.data
                })
            },
            selectChange(){
                this.$router.push({ path: '/bus/logTemplate', query: {}})
            },
            handleact(){
                if (this.goodsShare != null && this.goodsShare != ""&&this.goodsShare == 0){
                    this.temp.buyTheme = null;
                    this.temp.buyInfo = null;
                }
                if (this.goodsShare != null && this.goodsShare != ""&&this.goodsShare == 1){
                    this.temp.discountInfo = null;
                    this.temp.discountPrice = null;
                    this.temp.actInfo = null;
                }
                if (this.goodsShare != null && this.goodsShare != ""&&this.goodsShare == 2){
                    this.temp.discountInfo = null;
                    this.temp.discountPrice = null;
                    this.temp.actInfo = null;
                    this.temp.buyTheme = null;
                    this.temp.buyInfo = null;
                }
            },

            changeStockSku(name) {

                this.temp.mallSkus.forEach(sku => {

                    if (sku.name == name) {
                        this.stock.oldQuantity = sku.stock
                    }
                })
            },
            updateSku(themeList, skuList) {
                this.temp.skuThemes = themeList
                this.temp.mallSkus = skuList
            },
            getList() {
                this.listLoading = true
                list(this.listQuery).then(response => {
                    this.list = response.data.list
                    this.total = response.data.total
                    this.userId = response.extra.userId
                    this.roleId = response.extra.roleId
                    if (this.userId != null){
                        this.priceFlag=true;
                    }
                    this.listLoading = false
                })
            },
            handleFilter() {
                this.listQuery.type = this.types[1];

                this.listQuery.page = 1
                this.getList()
            },
            handleSizeChange(val) {
                this.listQuery.limit = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },
            handleModifyStatus(row, status) {
                this.$message({
                    message: '操作成功',
                    type: 'success'
                })
                row.status = status
            },
            beforeFormShow(row) {
                this.resetTemp(row) // 更新数据
                this.province = 1
                this.city = 2
                this.area = 3
                let initPrices = []
                this.fenLeiTypes = [];
                this.saleTypeInfoEntity = {};
                this.goodsTemp = {}
                this.bigTypes = [];
                this.shopReward = 5
                this.cashReward = null
                this.voucherReward = null
                this.clearReward = null
                this.maxClear = null
                this.maxCoupon = null
                this.couponReward = null
                this.goodsShare = null
                this.remnant = 200
                this.shopPrice = null
                this.act = {}
                // 初始化price
                this.levels.forEach(level => {
                    let price = {
                        levelId: level.id,
                        levelName: level.name,
                        price: null,
                        profit :null
                    }
                    initPrices.push(price)
                })
                this.temp.prices = initPrices;
                if (row) {
                    info(row.id).then(res => {
                        this.resetTemp(res.data)
                        if (res.extra.types){
                            this.fenLeiTypes = res.extra.types;
                        }
                        if (res.data.supplyPrice != null && res.data.supplyPrice != ''){
                            this.supplyPrice = res.data.supplyPrice
                        }
                        if (res.data.shopPrice != null && res.data.shopPrice != ''){
                            this.shopPrice = res.data.shopPrice
                        }
                        if(res.extra.act){
                            this.act = res.extra.act
                        }

                        if (this.fenLeiTypes != null && this.fenLeiTypes.length > 0) {
                            this.handleChange(this.fenLeiTypes)
                        }
                        if (this.temp.discountInfo != null && this.temp.discountInfo != ""){
                            this.goodsShare = 0;
                        }
                        if (this.temp.buyTheme != null && this.temp.buyTheme != ""){
                            this.goodsShare = 1;
                        }
                        if (res.extra.saleTypeInfoEntity == null) {
                            this.saleTypeInfoEntity.transfer = 0;
                            this.saleTypeInfoEntity.delivery = 0;
                        } else {
                            this.saleTypeInfoEntity = res.extra.saleTypeInfoEntity;
                        }

                        if (this.saleTypeInfoEntity.managerReward == null || this.saleTypeInfoEntity.managerReward == '') {
                            this.shopReward = 5
                        } else {
                            this.shopReward = this.saleTypeInfoEntity.managerReward * 100;
                        }
                        if (this.saleTypeInfoEntity.voucherReward != null && this.saleTypeInfoEntity.voucherReward != '') {
                            this.voucherReward = this.saleTypeInfoEntity.voucherReward.split("_")[1]
                        }
                        if (this.saleTypeInfoEntity.couponReward != null && this.saleTypeInfoEntity.couponReward != '') {
                            this.couponReward = this.saleTypeInfoEntity.couponReward.split("_")[1]
                        }
                        if (this.saleTypeInfoEntity.cashReward != null && this.saleTypeInfoEntity.cashReward != '') {
                            this.cashReward = this.saleTypeInfoEntity.cashReward.split("_")[1]
                        }
                        if (this.saleTypeInfoEntity.clearReward != null && this.saleTypeInfoEntity.clearReward != '') {
                            this.clearReward = this.saleTypeInfoEntity.clearReward.split("_")[1]
                        }
                        if (this.saleTypeInfoEntity.maxClear != null && this.saleTypeInfoEntity.maxClear != '') {
                            this.maxClear = this.saleTypeInfoEntity.maxClear
                        }
                        if (this.saleTypeInfoEntity.maxCoupon != null && this.saleTypeInfoEntity.maxCoupon != '') {
                            this.maxCoupon = this.saleTypeInfoEntity.maxCoupon
                        }
                        if (this.saleTypeInfoEntity.areaReward != null && this.saleTypeInfoEntity.areaReward != '') {
                            if (this.saleTypeInfoEntity.areaReward != '0_0_0') {
                                this.province = this.saleTypeInfoEntity.areaReward.split("_")[0]
                                this.city = this.saleTypeInfoEntity.areaReward.split("_")[1]
                                this.area = this.saleTypeInfoEntity.areaReward.split("_")[2]
                            } else {
                                this.province = 1
                                this.city = 2
                                this.area = 3
                            }
                        }

                        if (res.extra.goodsQualificationEntity) {
                            this.goodsTemp = res.extra.goodsQualificationEntity;
                        }
                        this.fenLeiTypes.forEach(item => {
                            if (!this.bigTypes.includes(item[0])) {
                                this.bigTypes.push(item[0])
                            }
                        })
                        this.temp.prices = initPrices
                        for (let i = 0; i < this.temp.prices.length; i++) {
                            for (let j = 0; j < res.data.prices.length; j++) {
                                if (this.temp.prices[i].levelId == res.data.prices[j].levelId) {
                                    this.temp.prices[i] = Object.assign(this.temp.prices[i], res.data.prices[j])
                                }
                            }
                        }
                        // 存在图片字段转换图片地址显示
                        this.initImgUrl()
                        this.dialogStatus = 'update'
                        this.dialogFormVisible = true;
                        this.$nextTick(() => {
                            this.$refs['dataForm'].clearValidate()
                        })
                    })
                }


                // 存在图片
                this.initQiniu()


            },
            afterFormShow(row) {

            },
            beforeFormCommit() {
                this.initImgName()// 图片转换
            },
            resetTemp(row) {
                if (row) {
                    this.temp = Object.assign({}, row) // copy obj
                    let num = this.temp.info  ?this.temp.info.length:0
                    this.remnant = this.maxRemnant - num
                } else {
                    this.temp = {prices: []}
                }

            },
            handleCreate() {
                this.beforeFormShow()
                // this.resetTemp()
                this.resetImgUrl()
                this.goodsShare = null
                this.shopPrice = null
                this.province = 1
                this.city = 2
                this.area = 3
                this.dialogStatus = 'create'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.afterFormShow()
                    this.$refs['dataForm'].clearValidate()
                })
            },
            // handleAdjust(row){调整
            //     this.dialogStatus = 'adjust'
            //     this.adjustFlag = true
            //     this.saleTypeFlag = true
            //     this.imgDiv ="imgNewDiv"
            //     this.handleUpdate(row)
            // },
            handleDelete(row) {
                this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // this.$message({
                    //   type: 'success',
                    //   message: '删除成功!'
                    // })
                    this.deleteData([row.id])
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
            },
            // 显示将图片名封装成可以展示状态集合
            initImgUrl() {
                this.imgList = strsToList(this.temp.img, domain)
                this.bigImgList = strsToList(this.temp.bigImg, domain)
                this.midImgList = strsToList(this.temp.midImg, domain)
                this.postImgList = strsToList(this.temp.postImg, domain)
                this.brandBusinessLicenseList = strsToList(this.goodsTemp.brandBusinessLicense, domain)
                this.companyHealthLicenseList = strsToList(this.goodsTemp.companyHealthLicense, domain)
                this.manageHealthLicenseList = strsToList(this.goodsTemp.manageHealthLicense, domain)
                this.approveLicenseList = strsToList(this.goodsTemp.approveLicense, domain)
                this.produceLicenseList = strsToList(this.goodsTemp.produceLicense, domain)
                this.registerNoticeList = strsToList(this.goodsTemp.registerNotice, domain)
                this.manageLicenseList = strsToList(this.goodsTemp.manageLicense, domain)
                this.gmpLicenseList = strsToList(this.goodsTemp.gmpLicense, domain)
                this.trademarkLicenseList = strsToList(this.goodsTemp.trademarkLicense, domain)
                this.productAgreementList = strsToList(this.goodsTemp.productAgreement, domain)
                this.circulateLicenseList = strsToList(this.goodsTemp.circulateLicense, domain)
                this.betweenCirculateLicenseList = strsToList(this.goodsTemp.betweenCirculateLicense, domain)
                this.detectPhotocopyList = strsToList(this.goodsTemp.detectPhotocopy, domain)
                this.goodsDeclarationList = strsToList(this.goodsTemp.goodsDeclaration, domain)
                this.productListList = strsToList(this.goodsTemp.productList, domain)
                this.companyLicenseList = strsToList(this.goodsTemp.companyLicense, domain)
                this.entrustAgreementList = strsToList(this.goodsTemp.entrustAgreement, domain)
                this.qualityGuarantyList = strsToList(this.goodsTemp.qualityGuaranty, domain)
                this.healthPhotocopyList = strsToList(this.goodsTemp.healthPhotocopy, domain)
                this.fiveTrademarkList = strsToList(this.goodsTemp.fiveTrademark, domain)
                this.recordTableList = strsToList(this.goodsTemp.recordTable, domain)
                this.epidemicPreventionList = strsToList(this.goodsTemp.epidemicPrevention, domain)
                this.industryLicenseList = strsToList(this.goodsTemp.industryLicense, domain)
                this.salesAuthorizationList = strsToList(this.goodsTemp.salesAuthorization, domain)
                this.testProveList = strsToList(this.goodsTemp.testProve, domain)
                this.cccLicenseList = strsToList(this.goodsTemp.cccLicense, domain)
                this.goodsProveList = strsToList(this.goodsTemp.goodsProve, domain)
                this.brandAuthorizationList = strsToList(this.goodsTemp.brandAuthorization, domain)
            },
            // 关闭显示窗口 重置图片地址 防止错乱
            resetImgUrl() {
                this.imgList = []
                this.bigImgList = []
                this.midImgList = []
                this.postImgList = []
                this.brandBusinessLicenseList = []
                this.companyHealthLicenseList = []
                this.manageHealthLicenseList = []
                this.approveLicenseList = []
                this.produceLicenseList = []
                this.registerNoticeList = []
                this.manageLicenseList = []
                this.gmpLicenseList = []
                this.trademarkLicenseList = []
                this.productAgreementList = []
                this.circulateLicenseList = []
                this.betweenCirculateLicenseList = []
                this.detectPhotocopyList = []
                this.goodsDeclarationList = []
                this.productListList = []
                this.companyLicenseList = []
                this.entrustAgreementList = []
                this.qualityGuarantyList = []
                this.healthPhotocopyList = []
                this.fiveTrademarkList = []
                this.recordTableList = []
                this.epidemicPreventionList = []
                this.industryLicenseList = []
                this.salesAuthorizationList = []
                this.testProveList = []
                this.cccLicenseList = []
                this.goodsProveList = []
                this.brandAuthorizationList = []

            },
            // 上传或者更新的时候从图片链接中获取图片名字
            initImgName() {
                this.temp.img = listToStrs(this.imgList)
                this.temp.bigImg = listToStrs(this.bigImgList)
                this.temp.midImg = listToStrs(this.midImgList)
                this.temp.postImg = listToStrs(this.postImgList)
                this.goodsTemp.brandBusinessLicense = listToStrs(this.brandBusinessLicenseList)
                this.goodsTemp.companyHealthLicense = listToStrs(this.companyHealthLicenseList)
                this.goodsTemp.manageHealthLicense = listToStrs(this.manageHealthLicenseList)
                this.goodsTemp.approveLicense = listToStrs(this.approveLicenseList)
                this.goodsTemp.produceLicense = listToStrs(this.produceLicenseList)
                this.goodsTemp.registerNotice = listToStrs(this.registerNoticeList)
                this.goodsTemp.manageLicense = listToStrs(this.manageLicenseList)
                this.goodsTemp.gmpLicense = listToStrs(this.gmpLicenseList)
                this.goodsTemp.trademarkLicense = listToStrs(this.trademarkLicenseList)
                this.goodsTemp.productAgreement = listToStrs(this.productAgreementList)
                this.goodsTemp.circulateLicense = listToStrs(this.circulateLicenseList)
                this.goodsTemp.betweenCirculateLicense = listToStrs(this.betweenCirculateLicenseList)
                this.goodsTemp.detectPhotocopy = listToStrs(this.detectPhotocopyList)
                this.goodsTemp.goodsDeclaration = listToStrs(this.goodsDeclarationList)
                this.goodsTemp.productList = listToStrs(this.productListList)
                this.goodsTemp.companyLicense = listToStrs(this.companyLicenseList)
                this.goodsTemp.entrustAgreement = listToStrs(this.entrustAgreementList)
                this.goodsTemp.qualityGuaranty = listToStrs(this.qualityGuarantyList)
                this.goodsTemp.healthPhotocopy = listToStrs(this.healthPhotocopyList)
                this.goodsTemp.fiveTrademark = listToStrs(this.fiveTrademarkList)
                this.goodsTemp.recordTable = listToStrs(this.recordTableList)
                this.goodsTemp.epidemicPrevention = listToStrs(this.epidemicPreventionList)
                this.goodsTemp.industryLicense = listToStrs(this.industryLicenseList)
                this.goodsTemp.salesAuthorization = listToStrs(this.salesAuthorizationList)
                this.goodsTemp.testProve = listToStrs(this.testProveList)
                this.goodsTemp.cccLicense = listToStrs(this.cccLicenseList)
                this.goodsTemp.goodsProve = listToStrs(this.goodsProveList)
                this.goodsTemp.brandAuthorization = listToStrs(this.brandAuthorizationList)
            },
            initData() {
                if (!this.temp.stock) {
                    this.temp.stock = 0
                }
            },
            createData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            this.temp['json'] = true
                            this.initData();
                            if (this.temp.saleType == 5){
                                if (this.cashReward == null || this.cashReward == ""){
                                    this.$message.error("代金券奖励为必填项");
                                    return;
                                }
                                if (this.voucherReward == null || this.voucherReward == ""){
                                    this.$message.error("换购券奖励为必填项");
                                    return;
                                }
                                if (this.cashReward < this.shopPrice *100 /1000){
                                    this.$message.error("代金券奖励不能小于采购价的10%");
                                    return;
                                }
                                if (this.voucherReward < this.shopPrice *100 /1000){
                                    this.$message.error("换购券奖励不能小于采购价的10%");
                                    return;
                                }
                            }
                            if (this.goodsShare != null && this.goodsShare == 0){
                                if (this.temp.discountInfo == null || this.temp.discountInfo == "" || this.temp.discountInfo.length > 4){
                                    this.$message.error("优惠描述只能是四个字以内")
                                    return;
                                }
                                if (this.temp.actInfo == null || this.temp.actInfo == "" || this.temp.actInfo.length > 8){
                                    this.$message.error("活动信息八个字内")
                                    return;
                                }
                            }
                            if (this.goodsShare != null && this.goodsShare == 1){
                                if (this.temp.buyTheme == null || this.temp.buyTheme == "" || this.temp.buyTheme.length > 4){
                                    this.$message.error("卖点主题四个字内")
                                    return;
                                }
                                if (this.temp.buyInfo == null || this.temp.buyInfo == "" || this.temp.buyInfo.length > 8){
                                    this.$message.error("卖点信息八个字内")
                                    return;
                                }
                            }
                            console.log(this.supplyPrice)
                            if (this.userId != null && this.userId != '') {
                                // if (this.goodsTemp.brandAuthorization == null || this.goodsTemp.brandAuthorization == "") {
                                //     this.$alert('请上传品牌方承诺书或授权书', {
                                //         confirmButtonText: '确定',
                                //     })
                                //     return;
                                // }
                                if (this.flTypes == null || this.fenLeiTypes.length == 0) {
                                    this.$message({
                                        showClose: true,
                                        message: '请填写分类',
                                        type: 'error'
                                    });
                                    return;
                                }
                                if (this.goodsTemp.brandName == null || this.goodsTemp.brandName == '') {
                                    this.$message.error("请填写品牌名称")
                                    return;
                                }
                                if (this.goodsTemp.brandInfo == null || this.goodsTemp.brandInfo == '') {
                                    this.$message.error("请填写品牌简介")
                                    return;
                                }
                                if (this.province == null || this.province == ''
                                    || this.city == null || this.city == ''
                                    || this.area == null || this.area == '') {
                                    this.$message.error("请填写区域服务津贴")
                                    return;
                                }
                                if (this.temp.logType == 2){
                                    if (this.temp.logTemId == null || this.temp.logTemId == '') {
                                        this.$message({
                                            showClose: true,
                                            message: '请选择物流模板',
                                            type: 'error'
                                        });
                                        return;
                                    }
                                }
                                if (this.shopReward < 5) {
                                    this.$message.error("店铺服务津贴不能少于5%");
                                    return;
                                }

                                if (this.temp.saleType == 1){
                                    if (this.supplyPrice == null || this.supplyPrice == ''){
                                        this.$message.error("请填写供货价")
                                        return;
                                    }else {
                                        this.temp.supplyPrice=this.supplyPrice
                                    }
                                }
                            }
                            if (this.temp.saleType == 17){
                                this.saleTypeInfoEntity.managerReward = null
                                this.saleTypeInfoEntity.areaReward = null
                                if (this.maxClear != null && this.maxClear != ''){
                                    this.saleTypeInfoEntity.maxClear = this.maxClear
                                }
                            }else {
                                this.saleTypeInfoEntity.maxClear = null
                                this.saleTypeInfoEntity.clearReward = null
                                this.saleTypeInfoEntity.managerReward = this.shopReward / 100
                                if (this.province != null && this.province != '') {
                                    this.saleTypeInfoEntity.areaReward = this.province
                                }
                                if (this.city != null && this.city != '') {
                                    this.saleTypeInfoEntity.areaReward = this.saleTypeInfoEntity.areaReward + "_" + this.city
                                }
                                if (this.area != null && this.area != '') {
                                    this.saleTypeInfoEntity.areaReward = this.saleTypeInfoEntity.areaReward + "_" + this.area
                                }
                                if (this.voucherReward != null && this.voucherReward != '') {
                                    this.saleTypeInfoEntity.voucherReward = "0_" + this.voucherReward
                                }
                                if (this.couponReward != null && this.couponReward != '') {
                                    this.saleTypeInfoEntity.couponReward = "0_" + this.couponReward
                                }
                                if (this.cashReward != null && this.cashReward != '') {
                                    this.saleTypeInfoEntity.cashReward = "0_" + this.cashReward
                                }
                                if (this.maxCoupon != null && this.maxCoupon != ''){
                                    this.saleTypeInfoEntity.maxCoupon = this.maxCoupon
                                }

                            }
                            if (this.shopPrice != null &&  this.shopPrice != ''){
                                this.temp.shopPrice = this.shopPrice
                            }
                            if (this.clearReward != null && this.clearReward != '') {
                                this.saleTypeInfoEntity.clearReward = "0_" + this.clearReward
                            }
                            save(this.temp, this.saleTypeInfoEntity, this.flTypes, this.goodsTemp,this.act).then(res => {
                                this.temp = res.data
                                this.list.unshift(this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '创建成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            deleteData(ids) {
                // const ids = [this.temp.id]
                remove({ids: ids}).then(res => {
                    // 从当前队列中移除
                    for (const v of this.list) {
                        if (ids.indexOf(v.id) > -1) {
                            const index = this.list.indexOf(v)
                            this.list.splice(index, 1)
                            break
                        }
                    }
                    this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    })
                })
            },
            handleStock(scope) {
                this.$index = scope.$index
                info(scope.row.id).then(res => {
                    this.temp = Object.assign({}, res.data)
                    this.stock.goodsName = this.temp.name
                    this.stock.goodsId = this.temp.id
                    this.stock.quantity = 0
                    this.stock.remark = ""
                    this.stock.skuName = ""
                    this.stock.oldQuantity = this.temp.quantity ? this.temp.quantity : 0
                    this.dialogStockVisible = true
                })


            },
            updateStock() {
                updateStock(this.stock).then(res => {
                    this.dialogStockVisible = false
                    this.$notify({
                        title: '成功',
                        message: '修改库存成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.list.splice(this.$index, 1, res.data)
                })
            },
            handleUpdate(row) {

                this.beforeFormShow(row)
                if (this.userId!=null){
                    this.saleTypeFlag = true
                }

            },
            handleChange(value) {
                this.flTypes = value;
                let fl = [];
                let bigTypes = [];
                this.flTypes.forEach(item => {
                    fl.push(item[1])
                    bigTypes.push(item[0])
                })
                this.flTypes = fl;
                this.bigTypes = bigTypes
            },
            updateData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {

                            this.beforeFormCommit()
                            if (this.temp.saleType == 5){
                                if (this.cashReward == null || this.cashReward == ""){
                                    this.$message.error("代金券奖励为必填项");
                                    return;
                                }
                                if (this.voucherReward == null || this.voucherReward == ""){
                                    this.$message.error("换购券奖励为必填项");
                                    return;
                                }
                                if (this.cashReward < this.shopPrice *100 /1000){
                                    this.$message.error("代金券奖励不能小于采购价的10%");
                                    return;
                                }
                                if (this.voucherReward < this.shopPrice *100 /1000){
                                    this.$message.error("换购券奖励不能小于采购价的10%");
                                    return;
                                }
                            }
                            if(this.goodsShare != null && this.goodsShare == 0){

                                if (this.temp.discountInfo == null || this.temp.discountInfo == "" || this.temp.discountInfo.length > 4){
                                    this.$message.error("优惠描述只能是四个字以内")
                                    return;
                                }
                                if (this.temp.actInfo == null || this.temp.actInfo == "" || this.temp.actInfo.length > 8){
                                    this.$message.error("活动信息八个字内")
                                    return;
                                }
                                this.temp.buyTheme = ""
                                this.temp.buyInfo = ""
                            }
                            if(this.goodsShare != null && this.goodsShare == 1){
                                if (this.temp.buyTheme == null || this.temp.buyTheme == "" || this.temp.buyTheme.length > 4){
                                    this.$message.error("卖点主题四个字内")
                                    return;
                                }
                                if (this.temp.buyInfo == null || this.temp.buyInfo == "" || this.temp.buyInfo.length > 8){
                                    this.$message.error("卖点信息八个字内")
                                    return;
                                }
                                this.temp.discountInfo = "";
                                this.temp.discountPrice = 0;
                                this.temp.actInfo = "";
                            }
                            if (this.goodsShare != null && this.goodsShare!=''&& this.goodsShare == 2){
                                this.temp.discountInfo = "";
                                this.temp.discountPrice = 0;
                                this.temp.actInfo = "";
                                this.temp.buyTheme = ""
                                this.temp.buyInfo = ""
                            }

                            if (this.userId != null) {
                                // if (this.goodsTemp.brandAuthorization == null || this.goodsTemp.brandAuthorization == "") {
                                //     this.$alert('请上传品牌方承诺书或授权书', {
                                //         confirmButtonText: '确定',
                                //     })
                                //     return;
                                // }
                                if (this.flTypes == null || this.fenLeiTypes.length == 0) {
                                    this.$message({
                                        showClose: true,
                                        message: '请填写分类',
                                        type: 'error'
                                    });
                                    return;
                                }
                                if (this.temp.logType == 2){
                                    if (this.temp.logTemId == null || this.temp.logTemId == '') {
                                        this.$message({
                                            showClose: true,
                                            message: '请选择物流模板',
                                            type: 'error'
                                        });
                                        return;
                                    }
                                }

                                if (this.goodsTemp.brandName == null || this.goodsTemp.brandName == '') {
                                    this.$message.error("请填写品牌名称")
                                    return;
                                }
                                if (this.goodsTemp.brandInfo == null || this.goodsTemp.brandInfo == '') {
                                    this.$message.error("请填写品牌简介")
                                    return;
                                }
                                if (this.province == null || this.province == ''
                                    || this.city == null || this.city == ''
                                    || this.area == null || this.area == '') {
                                    this.$message.error("请填写区域服务津贴")
                                    return;
                                }
                                if (this.temp.saleType == 1){
                                    if (this.supplyPrice == null || this.supplyPrice == ''){
                                        this.$message.error("请填写供货价")
                                        return;
                                    }
                                }
                            }
                            if (this.supplyPrice != null && this.supplyPrice != ''){
                                this.temp.supplyPrice=this.supplyPrice;
                            }
                            this.temp['json'] = true
                            // this.temp.prices =this.prices
                            if (this.userId != null && this.userId != '') {
                                if (this.shopReward < 5) {
                                    this.$message.error("店铺服务津贴不能少于5%");
                                    return;
                                }
                            }
                            if (this.maxClear != null && this.maxClear != ''){
                                this.saleTypeInfoEntity.maxClear = this.maxClear
                            }
                            this.saleTypeInfoEntity.managerReward = this.shopReward / 100
                            if (this.province != null && this.province != '') {
                                this.saleTypeInfoEntity.areaReward = this.province
                            }
                            if (this.city != null && this.city != '') {
                                this.saleTypeInfoEntity.areaReward = this.saleTypeInfoEntity.areaReward + "_" + this.city
                            }
                            if (this.area != null && this.area != '') {
                                this.saleTypeInfoEntity.areaReward = this.saleTypeInfoEntity.areaReward + "_" + this.area
                            }
                            if (this.voucherReward != null && this.voucherReward != '') {
                                this.saleTypeInfoEntity.voucherReward = "0_" + this.voucherReward
                            }
                            if (this.couponReward != null && this.couponReward != '') {
                                this.saleTypeInfoEntity.couponReward = "0_" + this.couponReward
                            }
                            if (this.cashReward != null && this.cashReward != '') {
                                this.saleTypeInfoEntity.cashReward = "0_" + this.cashReward
                            }
                            if (this.maxCoupon != null && this.maxCoupon != ''){
                                this.saleTypeInfoEntity.maxCoupon = this.maxCoupon
                            }
                            if (this.clearReward != null && this.clearReward != '') {
                                this.saleTypeInfoEntity.clearReward = "0_" + this.clearReward
                            }
                            this.temp.shopPrice = this.shopPrice
                            if (this.userId != null){
                                this.saleTypeInfoEntity.couponReward = 0
                            }

                            update(this.temp, this.saleTypeInfoEntity, this.flTypes, this.goodsTemp,this.act,this.adjustFlag).then((res) => {
                                for (const v of this.list) {
                                    if (v.id === this.temp.id) {
                                        if (this.temp.id == res.data.id) {
                                            this.temp = res.data
                                        }
                                        const index = this.list.indexOf(v)
                                        this.list.splice(index, 1, this.temp)
                                        break
                                    }
                                }

                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '更新成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            closeDialogForm() {
                // 存在图片
                this.resetImgUrl()
                this.fenLeiTypes = [];
                this.province = null
                this.city = null
                this.area = null
                this.dialogFormVisible = false
                this.saleTypeInfoEntity.managerReward = 5
                this.shopPrice = null
                this.saleTypeFlag=false
                this.supplyPrice=null
                this.imgDiv='imgDiv'
            },
            handleDownload() {
                this.downloadLoading = true
                import('@/vendor/Export2Excel').then(excel => {
                    const tHeader = [
                        '序号'
                        ,
                        '上传者的ID'
                        ,
                        '所属分类'
                        ,
                        '产品名字'
                        ,
                        '单位'
                        ,
                        '虚拟销量'
                        ,
                        '产品重量kg'
                        ,
                        '描述'
                        ,
                        '分享标题'
                        ,
                        '原价'
                        ,
                        '现价'
                        ,
                        '利润'
                        ,
                        '排序'
                        ,
                        '库存'
                        ,
                        '开启规格'
                        ,
                        '是否上架'
                    ]
                    const filterVal = ['id'
                        , 'userId'
                        , 'type'
                        , 'name'
                        , 'unit'
                        , 'sales'
                        , 'weight'
                        , 'info'
                        , 'title'
                        , 'oldPrice'
                        , 'nowPrice'
                        , 'profit'
                        , 'sort'
                        , 'stock'
                        ,
                        'openSku'
                        ,
                        'shelf'
                    ]
                    const data = this.formatJson(filterVal, this.list)
                    excel.export_json_to_excel({
                        header: tHeader,
                        data,
                        filename: 'table-list'
                    })
                    this.downloadLoading = false
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => {
                        return v[j]
                    }
                ))
            },
            // 存在图片
            handleUpload(file) {
                this.qData.key = new Date().valueOf() + file.name
            },
            initQiniu() {
                // 获取七牛配置
                getToken().then(res => {
                    this.qData.token = res.data
                }).catch(error => {
                    console.log(error)
                })
            },
            handleimgUploadSuccess(response, file, fileList) {
                this.imgList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlebigImgUploadSuccess(response, file, fileList) {
                this.bigImgList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlemidImgUploadSuccess(response, file, fileList) {
                this.midImgList.push({name: file.response.key, url: domain + file.response.key})
            },
            handlepostImgUploadSuccess(response, file, fileList) {
                this.postImgList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleimgRemove(file, fileList) {
                for (var fn of this.imgList) {
                    if (fn.name === file.name) {
                        this.imgList.splice(this.imgList.indexOf(fn), 1)
                    }
                }
            },
            handlebigImgRemove(file, fileList) {
                for (var fn of this.bigImgList) {
                    if (fn.name === file.name) {
                        this.bigImgList.splice(this.bigImgList.indexOf(fn), 1)
                    }
                }
            },
            handlemidImgRemove(file, fileList) {
                for (var fn of this.midImgList) {
                    if (fn.name === file.name) {
                        this.midImgList.splice(this.midImgList.indexOf(fn), 1)
                    }
                }
            }, handlepostImgRemove(file, fileList) {
                for (var fn of this.postImgList) {
                    if (fn.name === file.name) {
                        this.postImgList.splice(this.postImgList.indexOf(fn), 1)
                    }
                }
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url
                this.dialogVisible = true
            },
            handlecompanyhealthLicenseUploadSuccess(response, file, fileList) {
                this.companyHealthLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlemanagehealthLicenseUploadSuccess(response, file, fileList) {
                this.manageHealthLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleapproveLicenseUploadSuccess(response, file, fileList) {
                this.approveLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleproduceLicenseUploadSuccess(response, file, fileList) {
                this.produceLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,

            handlemanageLicenseUploadSuccess(response, file, fileList) {
                this.manageLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlegmpLicenseUploadSuccess(response, file, fileList) {
                this.gmpLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handletrademarkLicenseUploadSuccess(response, file, fileList) {
                this.trademarkLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleproductAgreementUploadSuccess(response, file, fileList) {
                this.productAgreementList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlecirculateLicenseUploadSuccess(response, file, fileList) {
                this.circulateLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handledetectPhotocopyUploadSuccess(response, file, fileList) {
                this.detectPhotocopyList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlegoodsDeclarationUploadSuccess(response, file, fileList) {
                this.goodsDeclarationList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleproductListUploadSuccess(response, file, fileList) {
                this.productListList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlecompanyLicenseUploadSuccess(response, file, fileList) {
                this.companyLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleentrustAgreementUploadSuccess(response, file, fileList) {
                this.entrustAgreementList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlequalityGuarantyUploadSuccess(response, file, fileList) {
                this.qualityGuarantyList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlerecordTableUploadSuccess(response, file, fileList) {
                this.recordTableList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleepidemicPreventionUploadSuccess(response, file, fileList) {
                this.epidemicPreventionList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handleindustryLicenseUploadSuccess(response, file, fileList) {
                this.industryLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlesalesAuthorizationUploadSuccess(response, file, fileList) {
                this.salesAuthorizationList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handletestProveUploadSuccess(response, file, fileList) {
                this.testProveList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlecccLicenseUploadSuccess(response, file, fileList) {
                this.cccLicenseList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlegoodsProveUploadSuccess(response, file, fileList) {
                this.goodsProveList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlebrandAuthorizationUploadSuccess(response, file, fileList) {
                this.brandAuthorizationList.push({name: file.response.key, url: domain + file.response.key})
            }
            ,
            handlecompanyhealthLicenseRemove(file, fileList) {
                for (var fn of this.companyHealthLicenseList) {
                    if (fn.name === file.name) {
                        this.companyHealthLicenseList.splice(this.companyHealthLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handlemanagehealthLicenseRemove(file, fileList) {
                for (var fn of this.manageHealthLicenseList) {
                    if (fn.name === file.name) {
                        this.manageHealthLicenseList.splice(this.manageHealthLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handleapproveLicenseRemove(file, fileList) {
                for (var fn of this.approveLicenseList) {
                    if (fn.name === file.name) {
                        this.approveLicenseList.splice(this.approveLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handleproduceLicenseRemove(file, fileList) {
                for (var fn of this.produceLicenseList) {
                    if (fn.name === file.name) {
                        this.produceLicenseList.splice(this.produceLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handlemanageLicenseRemove(file, fileList) {
                for (var fn of this.manageLicenseList) {
                    if (fn.name === file.name) {
                        this.manageLicenseList.splice(this.manageLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handlegmpLicenseRemove(file, fileList) {
                for (var fn of this.gmpLicenseList) {
                    if (fn.name === file.name) {
                        this.gmpLicenseList.splice(this.gmpLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handletrademarkLicenseRemove(file, fileList) {
                for (var fn of this.trademarkLicenseList) {
                    if (fn.name === file.name) {
                        this.trademarkLicenseList.splice(this.trademarkLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handleproductAgreementRemove(file, fileList) {
                for (var fn of this.productAgreementList) {
                    if (fn.name === file.name) {
                        this.productAgreementList.splice(this.productAgreementList.indexOf(fn), 1)
                    }
                }
            },
            handlecirculateLicenseRemove(file, fileList) {
                for (var fn of this.circulateLicenseList) {
                    if (fn.name === file.name) {
                        this.circulateLicenseList.splice(this.circulateLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handledetectPhotocopyRemove(file, fileList) {
                for (var fn of this.detectPhotocopyList) {
                    if (fn.name === file.name) {
                        this.detectPhotocopyList.splice(this.detectPhotocopyList.indexOf(fn), 1)
                    }
                }
            },
            handlegoodsDeclarationRemove(file, fileList) {
                for (var fn of this.goodsDeclarationList) {
                    if (fn.name === file.name) {
                        this.goodsDeclarationList.splice(this.goodsDeclarationList.indexOf(fn), 1)
                    }
                }
            },
            handleproductListRemove(file, fileList) {
                for (var fn of this.productListList) {
                    if (fn.name === file.name) {
                        this.productListList.splice(this.productListList.indexOf(fn), 1)
                    }
                }
            },
            handlecompanyLicenseRemove(file, fileList) {
                for (var fn of this.companyLicenseList) {
                    if (fn.name === file.name) {
                        this.companyLicenseList.splice(this.companyLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handleentrustAgreementRemove(file, fileList) {
                for (var fn of this.entrustAgreementList) {
                    if (fn.name === file.name) {
                        this.entrustAgreementList.splice(this.entrustAgreementList.indexOf(fn), 1)
                    }
                }
            },
            handlequalityGuarantyRemove(file, fileList) {
                for (var fn of this.qualityGuarantyList) {
                    if (fn.name === file.name) {
                        this.qualityGuarantyList.splice(this.qualityGuarantyList.indexOf(fn), 1)
                    }
                }
            },
            handlerecordTableRemove(file, fileList) {
                for (var fn of this.recordTableList) {
                    if (fn.name === file.name) {
                        this.recordTableList.splice(this.recordTableList.indexOf(fn), 1)
                    }
                }
            },
            handleepidemicPreventionRemove(file, fileList) {
                for (var fn of this.epidemicPreventionList) {
                    if (fn.name === file.name) {
                        this.epidemicPreventionList.splice(this.epidemicPreventionList.indexOf(fn), 1)
                    }
                }
            },
            handleindustryLicenseRemove(file, fileList) {
                for (var fn of this.industryLicenseList) {
                    if (fn.name === file.name) {
                        this.industryLicenseList.splice(this.industryLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handlesalesAuthorizationRemove(file, fileList) {
                for (var fn of this.salesAuthorizationList) {
                    if (fn.name === file.name) {
                        this.salesAuthorizationList.splice(this.salesAuthorizationList.indexOf(fn), 1)
                    }
                }
            },
            handletestProveRemove(file, fileList) {
                for (var fn of this.testProveList) {
                    if (fn.name === file.name) {
                        this.testProveList.splice(this.testProveList.indexOf(fn), 1)
                    }
                }
            },
            handlecccLicenseRemove(file, fileList) {
                for (var fn of this.cccLicenseList) {
                    if (fn.name === file.name) {
                        this.cccLicenseList.splice(this.cccLicenseList.indexOf(fn), 1)
                    }
                }
            },
            handlegoodsProveRemove(file, fileList) {
                for (var fn of this.goodsProveList) {
                    if (fn.name === file.name) {
                        this.goodsProveList.splice(this.goodsProveList.indexOf(fn), 1)
                    }
                }
            },
            handlebrandAuthorizationRemove(file, fileList) {
                for (var fn of this.brandAuthorizationList) {
                    if (fn.name === file.name) {
                        this.brandAuthorizationList.splice(this.brandAuthorizationList.indexOf(fn), 1)
                    }
                }
            },
        }
    }
</script>
